/**
 * indexDB打开数据库错误
 */
export default class IndexDBOpenError extends Error{
    private readonly dbName: string;
    private readonly dbVersion: number;
    private readonly originalError: DOMException | null
    private readonly errorName: string | undefined;
    private readonly errorInfo: string | undefined;
    constructor(dbName: string, dbVersion: number, originalError: DOMException | null) {
        const msg = originalError ? "ErrorType: " +  originalError.name + "\n\tErrorInfo: " + originalError.message : "";
        super("\n\tDatabaseName: " + dbName + "\n\tDatabaseVersion: " + String(dbVersion) + "\n\t" +msg);
        this.errorName = originalError?.name
        this.errorInfo = originalError?.message
        this.dbName = dbName;
        this.dbVersion = dbVersion;
        this.originalError = originalError;
        Object.setPrototypeOf(this, IndexDBOpenError.prototype);
    }

    toString(){
        return {
            name: this.name,
            errorName: this.errorName,
            errorInfo: this.errorInfo,
            message: this.message,
            dbName: this.dbName,
            dbVersion: this.dbVersion,
            other: this.originalError
        };
    }
}